﻿using ET.Monitor.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Data;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Web.Script.Serialization;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WebAPI.App_Code;
using System.Threading.Tasks;

namespace ET.Monitor.Web.Api
{
    public class MobileAppController : ApiController
    {
        StringHelper sh = new StringHelper();

        #region 公共功能

        #region 用户登录
        [HttpPost]
        public HttpResponseMessage CheckLogin()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string userName = request.Form["username"];
            string password = request.Form["password"];
            try
            {
                PersonnelModel pm = new PersonnelModel(userName, password);
                object ck = pm.ObjCheck;
                pm = new PersonnelModel(userName);
                string role = pm.Group;
                object obj = new
                {
                    judge = ck.ToString(),
                    uid = userName,
                    role = role
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：CheckLogin");
                sh.WriteLog("获取到参数：username:" + userName);
                sh.WriteLog("获取到参数：password:" + password);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion




        #endregion



        #region 集团总览
        [HttpPost]
        public HttpResponseMessage GetCliqueInfo()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string id = request.Form["id"];
            try
            {
                CliqueModel cm = new CliqueModel(id);

                object realPower = cm.ObjPower;
                object power = double.IsNaN(Convert.ToDouble(realPower)) ? null : realPower;

                double totalRL = cm.SumRL;
                object rl = double.IsNaN(totalRL) ? null : totalRL.ToString();

                double totalDL = cm.DlSumDL;
                object sumDL = double.IsNaN(totalDL) ? null : totalDL.ToString();

                StationModel sm = new StationModel(id);
                object dayYearDL = null;
                object dayDL = null;
                double daydl = sm.RealDL;

                dayDL = sh.GetDouble(daydl, 2).ToString();
                if (DateTime.Now.Month == 1 && DateTime.Now.Day == 1)
                    dayYearDL = dayDL;
                else
                {
                    cm = new CliqueModel(Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                    dayYearDL = cm.YearDL + daydl;
                }

                object bml = null;
                bml = sh.GetDouble(Convert.ToDouble(rl) / 1000 * 0.36, 2);
                object obj = new
                {
                    power = power,
                    rl = rl,
                    dl = sumDL,
                    bml = bml,
                    yearDL = sh.GetDouble(Convert.ToDouble(dayYearDL), 2),
                    dayDL = dayDL
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetCliqueInfo");
                sh.WriteLog("获取到参数：id:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetCliqueInfoNext()
        {

            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string id = request.Form["id"];
            string uid = request.Form["uid"];
            try
            {
                CliqueModel cm = new CliqueModel(id);

                object realPower = cm.ObjPower;
                object power = double.IsNaN(Convert.ToDouble(realPower)) ? null : realPower;

                double totalDL = cm.DlSumDL;
                object sumDL = double.IsNaN(totalDL) ? null : totalDL.ToString();

                StationModel sm = new StationModel(id);
                object dayYearDL = null;
                object dayDL = null;
                double daydl = sm.RealDL;

                if (!double.IsNaN(daydl) && daydl != -99999)
                {
                    dayDL = sh.GetDouble(daydl, 2).ToString();
                    if (DateTime.Now.Month == 1 && DateTime.Now.Day == 1)
                        dayYearDL = dayDL;
                    else
                    {
                        cm = new CliqueModel(Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                        dayYearDL = cm.YearDL + daydl;
                    }
                }

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();
                sm = new StationModel("'" + string.Join("','", stationID) + "'", "状态".Split(','));
                List<double[]> state = sm.RealVal;
                sm = new StationModel("'" + string.Join("','", stationID) + "'");
                DataTable dtRL = sm.AllRL;

                double rl = 0;

                for (int i = 0; i < stationID.Length; i++)
                {
                    if (state[0][i] != 0) rl += dtRL.AsEnumerable().Where(T => T.Field<string>("T_ORGID") == stationID[i]).Sum(s => s.Field<double>("d_rl"));
                }

                object bml = null;
                bml = sh.GetDouble(Convert.ToDouble(rl) / 1000 * 0.36, 2);
                object obj = new
                {
                    power = power,
                    rl = sh.GetDouble(rl, 2),
                    dl = sumDL,
                    bml = bml,
                    yearDL = sh.GetDouble(Convert.ToDouble(dayYearDL), 2),
                    dayDL = dayDL
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetCliqueInfoNext");
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 实时监控

        #region 获取省份
        [HttpPost]
        public HttpResponseMessage GetCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string userId = request.Form["userId"];
            try
            {
                PersonnelModel pm = new PersonnelModel(userId);
                DataTable dtStation = pm.DtPrivince;

                IList<Hashtable> list = new List<Hashtable>();
                for (int i = 0; i < dtStation.Rows.Count; i++)
                {
                    Hashtable ht = new Hashtable();
                    ht.Add("city", dtStation.Rows[i]["T_CITYDESC"]);
                    ht.Add("id", dtStation.Rows[i]["T_CITYID"]);
                    list.Add(ht);
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetCity");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 获取城市信息  根据省级编号
        [HttpPost]
        public HttpResponseMessage GetCityByPrivinceID()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string id = request.Form["ciytID"];
            try
            {
                OrgModel om = new OrgModel(id);
                IList<Hashtable> list = om.List;
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetCityByPrivinceID");
                sh.WriteLog("获取到参数：ciytID:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 获取  省、市、电站
        [HttpPost]
        public HttpResponseMessage GetLinkage()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string userId = request.Form["userId"];
            try
            {
                OrgModel om = new OrgModel(userId);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      

                if (dtStation != null && dtStation.Rows.Count > 0)
                {
                    DataTable dtCity = om.DtCity;

                    List<string> listCityID = new List<string>();
                    string[] cityID = dtStation.AsEnumerable().Select(x => x["T_CITYID"].ToString()).Distinct().ToArray();
                    for (int i = 0; i < cityID.Length; i++) listCityID.Add(cityID[i]);


                    List<string> listPrivinceID = new List<string>();
                    string[] privinceID = dtCity.AsEnumerable().Where(T => listCityID.Contains(T.Field<string>("T_CITYID").ToString())).Select(T => T["T_PARENTID"].ToString()).Distinct().ToArray();
                    for (int i = 0; i < privinceID.Length; i++) listPrivinceID.Add(privinceID[i]);
                    string[] privinceNmae = dtCity.AsEnumerable().Where(T => listPrivinceID.Contains(T.Field<string>("T_CITYID").ToString())).Select(T => T["T_CITYDESC"].ToString()).Distinct().ToArray();


                    IList<Hashtable> listPrivince = new List<Hashtable>();

                    for (int i = 0; i < privinceNmae.Length; i++)
                    {
                        Hashtable ht = new Hashtable();

                        string[] cityId = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == privinceID[i]).Select(T => T["T_CITYID"].ToString()).ToArray();
                        string[] cityName = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == privinceID[i]).Select(T => T["T_CITYDESC"].ToString()).Distinct().ToArray();

                        IList<Hashtable> listCity = new List<Hashtable>();
                        for (int k = 0; k < cityId.Length; k++)
                        {
                            Hashtable htCity = new Hashtable();
                            htCity.Add("id", cityId[k]);
                            htCity.Add("name", cityName[k]);

                            string[] stationId = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == cityId[k] && listCityID.Contains(T.Field<string>("T_CITYID").ToString())).Select(T => T["T_ORGID"].ToString()).ToArray();
                            string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == cityId[k] && listCityID.Contains(T.Field<string>("T_CITYID").ToString())).Select(T => T["T_PLANTDESC"].ToString()).ToArray();

                            IList<Hashtable> listStation = new List<Hashtable>();
                            for (int m = 0; m < stationId.Length; m++)
                            {
                                Hashtable htStation = new Hashtable();
                                htStation.Add("id", stationId[m]);
                                htStation.Add("name", stationName[m]);
                                listStation.Add(htStation);
                            }
                            htCity.Add("stations", listStation);

                            if (stationId.Length > 0)
                                listCity.Add(htCity);
                        }

                        ht.Add("id", privinceID[i]);
                        ht.Add("name", privinceNmae[i]);
                        ht.Add("citys", listCity);

                        listPrivince.Add(ht);
                    }

                    object obj = new
                    {
                        privince = listPrivince
                    };

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    string str = serializer.Serialize(obj);
                    HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                    return result;
                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetLinkage");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 电站列表 所有电站
        [HttpPost]
        public HttpResponseMessage GetPlantListAll()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string userId = request.Form["userId"];
            try
            {
                OrgModel om = new OrgModel(userId);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站       
                DataTable dtCity = om.DtCity;

                string[] arr = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", arr) + "'");
                DataTable dt_rl = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", arr) + "'", "负荷,电量,状态".Split(','));
                List<double[]> lt_powerdl = sm.RealVal;
                double[] d_dl = lt_powerdl[1];
                double[] d_Powre = lt_powerdl[0];
                double[] d_State = lt_powerdl[2];

                IList<Hashtable> list = new List<Hashtable>();

                int ar_num = 0;

                foreach (DataRow dr in dtStation.Rows)
                {
                    sm = new StationModel(dr["T_ORGID"].ToString());

                    DataRow[] drCity = dtCity.Select("T_CITYID='" + dr["T_CITYID"] + "'");
                    DataRow[] drPrivince = dtCity.Select("T_CITYID='" + drCity[0]["T_PARENTID"] + "'");

                    Hashtable ht = new Hashtable();
                    ar_num = Array.IndexOf(arr, dr["T_ORGID"].ToString());
                    if (double.IsNaN(d_Powre[ar_num]))
                        ht.Add("power", "");
                    else
                        ht.Add("power", Math.Round(d_Powre[ar_num], 2));
                    if (double.IsNaN(d_dl[ar_num]))
                        ht.Add("dl", "");
                    else
                        ht.Add("dl", Math.Round(d_dl[ar_num], 2));

                    DataRow[] dr_rl = dt_rl.Select("T_ORGID ='" + dr["T_ORGID"] + "'", "t_time desc");
                    if (dr_rl != null && dr_rl.Length > 0)
                        ht.Add("rl", dr_rl[0][3]);
                    else
                        ht.Add("rl", "");

                    ht.Add("cityID", drPrivince[0]["T_CITYID"]);
                    ht.Add("city", drPrivince[0]["T_CITYDESC"]);
                    ht.Add("id", dr["T_ORGID"]);
                    ht.Add("name", dr["T_PLANTDESC"]);
                    ht.Add("img", dr["T_IMGURL"]);

                    ht.Add("lat", dr["D_LAT"]);
                    ht.Add("long", dr["D_LONG"]);
                    if (double.IsNaN(d_State[ar_num]))
                        ht.Add("state", 0);
                    else
                        ht.Add("state", Convert.ToInt32(d_State[ar_num]));
                    list.Add(ht);
                    ar_num++;
                }

                object obj = new
                {
                    data = list
                };

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantListAll");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 省 下面电站
        [HttpPost]
        public HttpResponseMessage GetPlantListByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string userId = request.Form["userId"];
            string id = request.Form["ciytID"];
            try
            {
                OrgModel om = new OrgModel(userId);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站       
                DataTable dtCity = om.DtCity;

                string[] arr = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", arr) + "'");
                DataTable dt_rl = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", arr) + "'", "负荷,电量,状态".Split(','));

                List<double[]> lt_powerdl = sm.RealVal;
                double[] d_dl = lt_powerdl[1];
                double[] d_Powre = lt_powerdl[0];
                double[] d_State = lt_powerdl[2];

                int ar_num = 0;

                IList<Hashtable> list = new List<Hashtable>();

                for (int i = 0; i < arr.Length; i++)
                {
                    sm = new StationModel(arr[i]);
                    DataRow[] drStation = dtStation.Select("T_ORGID='" + arr[i] + "'");
                    DataRow[] drCity = dtCity.Select("T_CITYID='" + drStation[0]["T_CITYID"] + "'");
                    DataRow[] drPrivince = dtCity.Select("T_CITYID='" + drCity[0]["T_PARENTID"] + "'");

                    Hashtable ht = new Hashtable();
                    ar_num = Array.IndexOf(arr, arr[i]);
                    if (double.IsNaN(d_Powre[ar_num]))
                        ht.Add("power", "");
                    else
                        ht.Add("power", Math.Round(d_Powre[ar_num], 2));
                    if (double.IsNaN(d_dl[ar_num]))
                        ht.Add("dl", "");
                    else
                        ht.Add("dl", Math.Round(d_dl[ar_num], 2));

                    DataRow[] dr_rl = dt_rl.Select("T_ORGID ='" + arr[i] + "'", "t_time desc");
                    if (dr_rl != null && dr_rl.Length > 0)
                        ht.Add("rl", dr_rl[0][3]);
                    else
                        ht.Add("rl", "");

                    ht.Add("cityID", drPrivince[0]["T_CITYID"]);
                    ht.Add("city", drPrivince[0]["T_CITYDESC"]);

                    ht.Add("id", arr[i]);
                    ht.Add("name", drStation[0]["T_PLANTDESC"]);
                    ht.Add("img", drStation[0]["T_IMGURL"]);

                    ht.Add("lat", drStation[0]["D_LAT"]);
                    ht.Add("long", drStation[0]["D_LONG"]);
                    if (double.IsNaN(d_State[ar_num]))
                        ht.Add("state", 0);
                    else
                        ht.Add("state", Convert.ToInt32(d_State[ar_num]));
                    list.Add(ht);
                    ar_num++;
                }

                object obj = new
                {
                    data = list
                };

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantListByCity");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("获取到参数：ciytID:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 市 下面电站
        [HttpPost]
        public HttpResponseMessage GetPlantListByCityID()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string userId = request.Form["userId"];
            string id = request.Form["ciytID"];
            try
            {
                OrgModel om = new OrgModel(userId);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站       
                DataTable dtCity = om.DtCity;

                string[] arr = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", arr) + "'");
                DataTable dt_rl = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", arr) + "'", "负荷,电量,状态".Split(','));

                List<double[]> lt_powerdl = sm.RealVal;
                double[] d_dl = lt_powerdl[1];
                double[] d_Powre = lt_powerdl[0];
                double[] d_State = lt_powerdl[2];

                int ar_num = 0;

                IList<Hashtable> list = new List<Hashtable>();


                for (int i = 0; i < arr.Length; i++)
                {
                    sm = new StationModel(arr[i]);
                    DataRow[] drStation = dtStation.Select("T_ORGID='" + arr[i] + "'");
                    DataRow[] drCity = dtCity.Select("T_CITYID='" + drStation[0]["T_CITYID"] + "'");
                    DataRow[] drPrivince = dtCity.Select("T_CITYID='" + drCity[0]["T_PARENTID"] + "'");

                    Hashtable ht = new Hashtable();
                    ar_num = Array.IndexOf(arr, arr[i]);
                    if (double.IsNaN(d_Powre[ar_num]))
                        ht.Add("power", "");
                    else
                        ht.Add("power", Math.Round(d_Powre[ar_num], 2));
                    if (double.IsNaN(d_dl[ar_num]))
                        ht.Add("dl", "");
                    else
                        ht.Add("dl", Math.Round(d_dl[ar_num], 2));

                    DataRow[] dr_rl = dt_rl.Select("T_ORGID ='" + arr[i] + "'", "t_time desc");
                    if (dr_rl != null && dr_rl.Length > 0)
                        ht.Add("rl", dr_rl[0][3]);
                    else
                        ht.Add("rl", "");

                    ht.Add("cityID", drPrivince[0]["T_CITYID"]);
                    ht.Add("city", drPrivince[0]["T_CITYDESC"]);

                    ht.Add("id", arr[i]);
                    ht.Add("name", drStation[0]["T_PLANTDESC"]);
                    ht.Add("img", drStation[0]["T_IMGURL"]);

                    ht.Add("lat", drStation[0]["D_LAT"]);
                    ht.Add("long", drStation[0]["D_LONG"]);
                    if (double.IsNaN(d_State[ar_num]))
                        ht.Add("state", 0);
                    else
                        ht.Add("state", Convert.ToInt32(d_State[ar_num]));
                    list.Add(ht);
                    ar_num++;
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;

            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantListByCityID");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("获取到参数：ciytID:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 电站信息
        [HttpPost]
        public HttpResponseMessage GetPlantInfo()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string id = request.Form["id"];
            try
            {
                StationModel sm = new StationModel(id);
                string rl = "";// sm.RL;
                string dl = ""; //sm.RealDL;

                string power = "";
                string temperature = "";
                string humidity = "";
                string irradiance = "";
                string yearDL = "";
                string dayDL = "";
                string monthDL = "";

                object objUrl = sm.ObjUrl;

                double dlrl = sm.RL;
                double dldl = sm.DlSumDL;
                if (!double.IsNaN(dlrl))
                    rl = dlrl.ToString();
                if (!double.IsNaN(dldl))
                    dl = dldl.ToString();

                object objpower = sm.Power;
                if (!double.IsNaN(Convert.ToDouble(objpower)))
                    power = objpower.ToString();

                object objtemperature = sm.Temperature;
                if (!double.IsNaN(Convert.ToDouble(objtemperature)))
                    temperature = objtemperature.ToString();

                object objhumidity = sm.Humidity;
                if (!double.IsNaN(Convert.ToDouble(objhumidity)))
                    humidity = objhumidity.ToString();

                object objirradiance = sm.Irradiance;
                if (!double.IsNaN(Convert.ToDouble(objirradiance)))
                    irradiance = objirradiance.ToString();

                double inverterCount = sm.InverterCount;


                sm = new StationModel(id);
                object objdayDL = sm.RealDL;

                if (!double.IsNaN(Convert.ToDouble(objdayDL)) && Convert.ToDouble(objdayDL) != -99999)
                {
                    dayDL = objdayDL.ToString();

                    if (DateTime.Now.Month == 1 && DateTime.Now.Day == 1) yearDL = dayDL;
                    else
                    {
                        if (DateTime.Now.Day == 1) monthDL = dayDL;
                        else
                        {
                            sm = new StationModel(id, Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                            monthDL = (sh.GetDouble(sm.DL, 2) + Convert.ToDouble(dayDL)).ToString();
                        }
                        sm = new StationModel(id, Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                        yearDL = (sh.GetDouble(sm.DL, 2) + Convert.ToDouble(dayDL)).ToString();
                    }
                }

                OrgModel om = new OrgModel(id);
                string privince = om.StrPrivince;

                object obj = new
                {
                    rl = rl,
                    dl = dl,
                    power = power,
                    temperature = temperature,
                    humidity = humidity,
                    irradiance = irradiance,
                    inverterCount = sm.InverterCount,
                    yearDL = yearDL,
                    monthDL = monthDL,
                    dayDL = dayDL,
                    privince = privince,
                    img = objUrl
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantListByCityID");
                sh.WriteLog("获取到参数：id:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 监控数据

        #region 负荷趋势    曲线
        [HttpPost]
        public HttpResponseMessage GetPlantPowerLine()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string stationId = request.Form["stationId"];
            try
            {
                StationModel sm = new StationModel(stationId, Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 0:00:00")), DateTime.Now, 300);
                double[] line = sm.Line;
                string[] strLine = new string[line.Length];
                DateTime dtStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 0:00:00"));
                DateTime utcTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                long[] longs = new long[line.Length];
                long start = (long)(dtStart - utcTime).TotalMilliseconds;
                for (int i = 0; i < line.Length; i++)
                {
                    longs[i] = start + i * 300 * 1000;
                    line[i] = sh.GetDouble(line[i], 2);
                    if (!double.IsNaN(line[i]))
                        strLine[i] = sh.GetDouble(line[i], 2).ToString();
                    else
                        strLine[i] = "";
                }

                int seconds = (int)DateTime.Now.TimeOfDay.TotalSeconds;
                int totalTimes = seconds / 300;
                longs = longs.Take(totalTimes).ToArray();
                object obj = new
                {
                    timeSpan = longs,
                    line = strLine
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantPowerLine");
                sh.WriteLog("获取到参数：stationId:" + stationId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 电量趋势    柱形图
        [HttpPost]
        public HttpResponseMessage GetPlantDayDL()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string stationId = request.Form["stationId"];
            try
            {
                StationModel sm = new StationModel(stationId, Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 0:00:00")), DateTime.Now);

                DataTable dtDL = sm.DtTotalHourDL;

                IList<Hashtable> list = new List<Hashtable>();
                foreach (DataRow dr in dtDL.Rows)
                {
                    Hashtable ht = new Hashtable();
                    ht.Add("hour", dr["小时"]);
                    ht.Add("dl", dr["合计"]);
                    list.Add(ht);
                }
                object obj = new
                {
                    line = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantDayDL");
                sh.WriteLog("获取到参数：stationId:" + stationId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #endregion

        #region 设备信息
        [HttpPost]
        public HttpResponseMessage GetInterverInfo()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string stationId = request.Form["stationId"];
            IList<Hashtable> list = new List<Hashtable>();
            try
            {
                StationModel sm = new StationModel(stationId);
                DataTable dt = sm.DtInverters;

                string[] unitID = dt.AsEnumerable().Select(x => x["T_UNITID"].ToString()).ToArray();
                string[] unitName = dt.AsEnumerable().Select(x => x["T_UNITDESC_CN"].ToString()).ToArray();

                InverterModel im = new InverterModel("'" + string.Join("','", unitID) + "'", "负荷,电量".Split(','));
                List<double[]> values = im.List;


                if (values.Count > 0)
                {
                    double[] dls = values[1];
                    double[] powers = values[0];


                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("id", unitID);
                        ht.Add("name", unitName[i]);
                        if (powers[i] == -99999)
                            ht.Add("power", "");
                        else
                            ht.Add("power", sh.GetDouble(powers[i], 2));
                        if (dls[i] == -99999)
                            ht.Add("dayEle", "");
                        else
                            ht.Add("dayEle", sh.GetDouble(dls[i], 2));
                        list.Add(ht);
                    }
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetInterverInfo");
                sh.WriteLog("获取到参数：stationId:" + stationId);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 模糊收索电站
        [HttpPost]
        public HttpResponseMessage GetPlantByName()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string userId = request.Form["userId"];
            string name = request.Form["name"];
            try
            {
                StationModel sm = new StationModel(userId, name);
                DataTable dtStation = sm.DtStationName;
                IList<Hashtable> list = new List<Hashtable>();
                foreach (DataRow dr in dtStation.Rows)
                {
                    Hashtable ht = new Hashtable();
                    ht.Add("id", dr["T_ORGID"]);
                    ht.Add("name", dr["T_PLANTDESC"]);
                    list.Add(ht);
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPlantByName");
                sh.WriteLog("获取到参数：userId:" + userId);
                sh.WriteLog("获取到参数：name:" + name);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #endregion

        #region 设备故障

        #region 设备故障 信息
        [HttpPost]
        public HttpResponseMessage GetStationFault()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string uid = request.Form["uid"];

            try
            {
                DataTable dtOrg = new DataTable();
                OrgModel om = new OrgModel(uid);
                dtOrg = om.DtUserStation;
                IList<Hashtable> list = new List<Hashtable>();

                if (dtOrg != null)
                {
                    StationModel sm = new StationModel();
                    DataTable dtFault = sm.DtStationFaultDetaiCount;

                    if (dtFault != null && dtFault.Rows.Count > 0)
                    {
                        string[] arr = dtFault.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();

                        sm = new StationModel("'" + string.Join("','", arr) + "'", "负荷,电量".Split(','));
                        DataTable dt_rl = sm.AllRL;
                        List<double[]> lt_powerdl = sm.RealVal;
                        double[] d_dl = lt_powerdl[1];
                        double[] d_Powre = lt_powerdl[0];

                        for (int i = 0; i < dtFault.Rows.Count; i++)
                        {
                            DataRow[] dr = dtOrg.Select("T_ORGID='" + dtFault.Rows[i]["T_ORGID"] + "'");

                            if (dr != null && dr.Length > 0)
                            {
                                Hashtable ht = new Hashtable();
                                ht.Add("id", dr[0]["T_ORGID"]);
                                ht.Add("name", dr[0]["T_PLANTDESC"]);
                                ht.Add("cityID", dr[0]["T_CITYID"]);
                                ht.Add("cityName", dr[0]["T_CITYDESC"]);
                                ht.Add("img", dr[0]["T_IMGURL"]);
                                ht.Add("count", dtFault.Rows[i]["val"]);

                                if (!double.IsNaN(d_Powre[i]))
                                    ht.Add("power", d_Powre[i]);
                                else
                                    ht.Add("power", "");

                                if (!double.IsNaN(d_dl[i]))
                                    ht.Add("dl", d_dl[i]);
                                else
                                    ht.Add("dl", "");
                                DataTable dtFaultStation = new DataTable();
                                sm = new StationModel(dr[0]["T_ORGID"].ToString());
                                dtFaultStation = sm.RealFaultDtAll;

                                string[] strType = dtFaultStation.AsEnumerable().Where(T => T.Field<string>("T_TYPEDESC") == "正常").Select(T => T["T_TYPEDESC"].ToString()).ToArray();
                                if (strType.Length == dtFaultStation.Rows.Count)
                                    ht.Add("state", 0);
                                else
                                    ht.Add("state", 1);

                                list.Add(ht);
                            }
                        }
                    }
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFault");
                sh.WriteLog("获取到参数：uid:" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 根据省份搜索设别故障

        [HttpPost]
        public HttpResponseMessage GetStationFaultByProvince()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string uid = request.Form["uid"];
            string id = request.Form["id"];
            try
            {
                DataTable dtOrg = new DataTable();
                OrgModel om = new OrgModel(uid);
                dtOrg = om.DtUserStation;

                string[] stationID = dtOrg.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(T => T["T_ORGID"].ToString()).ToArray();

                IList<Hashtable> list = new List<Hashtable>();

                if (stationID.Length > 0)
                {
                    string[] stationName = dtOrg.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(T => T["T_PLANTDESC"].ToString()).ToArray();
                    string[] cityID = dtOrg.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(T => T["T_CITYID"].ToString()).ToArray();
                    string[] city = dtOrg.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(T => T["T_CITYDESC"].ToString()).ToArray();
                    string[] img = dtOrg.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(T => T["T_IMGURL"].ToString()).ToArray();

                    StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'");
                    DataTable dtFault = sm.DtFaultDetailInfo;

                    sm = new StationModel("'" + string.Join("','", stationID) + "'", "负荷,电量".Split(','));
                    List<double[]> lt_powerdl = sm.RealVal;
                    double[] d_dl = lt_powerdl[1];
                    double[] d_Powre = lt_powerdl[0];

                    for (int i = 0; i < stationID.Length; i++)
                    {
                        string[] faultCount = dtFault.AsEnumerable().Where(T => T.Field<string>("stationID") == stationID[i]).Select(T => T["T_ORGID"].ToString()).ToArray();

                        string[] strType = dtFault.AsEnumerable().Where(T => T.Field<string>("T_TYPEDESC") == "正常" && T.Field<string>("stationID") == stationID[i]).Select(T => T["T_TYPEDESC"].ToString()).ToArray();


                        if (faultCount.Length > 0)
                        {
                            Hashtable ht = new Hashtable();
                            ht.Add("id", stationID[i]);
                            ht.Add("name", stationName[i]);
                            ht.Add("cityID", cityID[i]);
                            ht.Add("cityName", city[i]);
                            ht.Add("img", img[i]);
                            ht.Add("count", faultCount.Length);
                            ht.Add("power", d_Powre[i]);
                            ht.Add("dl", d_dl[i]);

                            if (strType.Length == faultCount.Length)
                                ht.Add("state", 0);
                            else
                                ht.Add("state", 1);

                            list.Add(ht);
                        }
                    }
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFaultByProvince");
                sh.WriteLog("获取到参数：uid:" + uid);
                sh.WriteLog("获取到参数：id:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 根据  市 　搜索电站故障
        [HttpPost]
        public HttpResponseMessage GetStationFaultByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string uid = request.Form["uid"];
            string id = request.Form["cityID"];
            try
            {
                DataTable dtOrg = new DataTable();
                OrgModel om = new OrgModel(uid);
                dtOrg = om.DtUserStation;

                string[] stationID = dtOrg.AsEnumerable().Where(T => T.Field<string>("cityID") == id).Select(T => T["T_ORGID"].ToString()).ToArray();

                IList<Hashtable> list = new List<Hashtable>();

                if (stationID.Length > 0)
                {
                    string[] stationName = dtOrg.AsEnumerable().Where(T => T.Field<string>("cityID") == id).Select(T => T["T_PLANTDESC"].ToString()).ToArray();
                    string[] cityID = dtOrg.AsEnumerable().Where(T => T.Field<string>("cityID") == id).Select(T => T["T_CITYID"].ToString()).ToArray();
                    string[] city = dtOrg.AsEnumerable().Where(T => T.Field<string>("cityID") == id).Select(T => T["T_CITYDESC"].ToString()).ToArray();
                    string[] img = dtOrg.AsEnumerable().Where(T => T.Field<string>("cityID") == id).Select(T => T["T_IMGURL"].ToString()).ToArray();

                    StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'");
                    DataTable dtFault = sm.DtFaultDetailInfo;

                    sm = new StationModel("'" + string.Join("','", stationID) + "'", "负荷,电量".Split(','));
                    List<double[]> lt_powerdl = sm.RealVal;
                    double[] d_dl = lt_powerdl[1];
                    double[] d_Powre = lt_powerdl[0];

                    for (int i = 0; i < stationID.Length; i++)
                    {
                        string[] faultCount = dtFault.AsEnumerable().Where(T => T.Field<string>("stationID") == stationID[i]).Select(T => T["T_ORGID"].ToString()).ToArray();

                        string[] strType = dtFault.AsEnumerable().Where(T => T.Field<string>("T_TYPEDESC") == "正常" && T.Field<string>("stationID") == stationID[i]).Select(T => T["T_TYPEDESC"].ToString()).ToArray();

                        if (faultCount.Length > 0)
                        {
                            Hashtable ht = new Hashtable();
                            ht.Add("id", stationID[i]);
                            ht.Add("name", stationName[i]);
                            ht.Add("cityID", cityID[i]);
                            ht.Add("cityName", city[i]);
                            ht.Add("img", img[i]);
                            ht.Add("count", faultCount.Length);
                            ht.Add("power", d_Powre[i]);
                            ht.Add("dl", d_dl[i]);

                            if (strType.Length == faultCount.Length)
                                ht.Add("state", 0);
                            else
                                ht.Add("state", 1);

                            list.Add(ht);
                        }
                    }
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFaultByCity");
                sh.WriteLog("获取到参数：uid:" + uid);
                sh.WriteLog("获取到参数：cityID:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 根据  电站　搜索电站故障
        [HttpPost]
        public HttpResponseMessage GetStationFaultByID()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string id = request.Form["stationID"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                StationModel sm = new StationModel(id);
                DataTable dt = sm.DtFaultDetailInfo;

                sm = new StationModel("'" + string.Join("','", id.Split(',')) + "'", "负荷,电量".Split(','));
                List<double[]> lt_powerdl = sm.RealVal;
                double[] d_dl = lt_powerdl[1];
                double[] d_Powre = lt_powerdl[0];
                string[] strType = dt.AsEnumerable().Where(T => T.Field<string>("T_TYPEDESC") == "正常" && T.Field<string>("stationID") == id).Select(T => T["T_TYPEDESC"].ToString()).ToArray();



                if (dt != null && dt.Rows.Count > 0)
                {
                    Hashtable ht = new Hashtable();

                    if (strType.Length != dt.Rows.Count)
                    {
                        ht.Add("id", dt.Rows[0]["T_ORGID"]);
                        ht.Add("name", dt.Rows[0]["T_PLANTDESC"]);
                        ht.Add("count", dt.Rows.Count);
                        ht.Add("power", d_Powre[0]);
                        ht.Add("dl", d_dl[0]);
                        ht.Add("state", 1);
                        list.Add(ht);
                    }
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFaultByID");
                sh.WriteLog("获取到参数：stationID:" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 设备详细信息 单个
        [HttpPost]
        public HttpResponseMessage GetStationFaultInfo()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string stationID = request.Form["stationID"];
            int count = Convert.ToInt32(request.Form["count"]);
            int pageIndex = Convert.ToInt32(request.Form["pageIndex"]);

            try
            {
                StationModel sm = new StationModel(stationID, count, pageIndex);
                DataTable dt = sm.RealFaultDt;
                int totalCount = 0, page = 1;
                totalCount = sm.RealFaultCount;
                if (totalCount > 0)
                {
                    if (totalCount % count == 0 && totalCount / count > 0)
                        page = totalCount / count;
                    else
                        page = totalCount / count + 1;
                }

                IList<Hashtable> list = new List<Hashtable>();
                if (dt != null)
                    for (int k = 0; k < dt.Rows.Count; k++)
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("id", k + 1);
                        ht.Add("inverter", dt.Rows[k]["T_UNITDESC_CN"]);
                        ht.Add("faultName", dt.Rows[k]["T_FAULTDESC_CN"]);
                        ht.Add("grade", dt.Rows[k]["T_TYPEDESC"]);
                        if (dt.Rows[k]["T_STARTTIME"] != null && dt.Rows[k]["T_STARTTIME"].ToString() != "")
                            ht.Add("startTime", sh.DateTimeToUTC(Convert.ToDateTime(dt.Rows[k]["T_STARTTIME"].ToString())));
                        else
                            ht.Add("startTime", dt.Rows[k]["T_STARTTIME"]);
                        if (dt.Rows[k]["T_ENDTIME"] != null && dt.Rows[k]["T_ENDTIME"].ToString() != "")
                            ht.Add("endTime", sh.DateTimeToUTC(Convert.ToDateTime(dt.Rows[k]["T_ENDTIME"].ToString())));
                        else
                            ht.Add("endTime", dt.Rows[k]["T_ENDTIME"]);
                        list.Add(ht);
                    }

                object obj = new
                {
                    page = page,
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFaultInfo");
                sh.WriteLog("获取到参数：stationID:" + stationID);
                sh.WriteLog("获取到参数：count:" + count);
                sh.WriteLog("获取到参数：pageIndex:" + pageIndex);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 设备详细信息 单个(根据故障类型查询)
        [HttpPost]
        public HttpResponseMessage GetStationFaultInfoByType()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            string stationID = request.Form["stationID"];
            string type = request.Form["type"];
            int count = Convert.ToInt32(request.Form["count"]);
            int pageIndex = Convert.ToInt32(request.Form["pageIndex"]);

            try
            {
                StationModel sm = new StationModel(stationID, count, pageIndex, type);
                DataTable dt = sm.RealFaultDtType;
                int totalCount = 0, page = 1;
                totalCount = sm.RealFaultCountType;
                if (totalCount > 0)
                {
                    if (totalCount % count == 0 && totalCount / count > 0)
                        page = totalCount / count;
                    else
                        page = totalCount / count + 1;
                }

                IList<Hashtable> list = new List<Hashtable>();
                if (dt != null)
                    for (int k = 0; k < dt.Rows.Count; k++)
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("id", k + 1);
                        ht.Add("inverter", dt.Rows[k]["T_UNITDESC_CN"]);
                        ht.Add("faultName", dt.Rows[k]["T_FAULTDESC_CN"]);
                        ht.Add("grade", dt.Rows[k]["T_TYPEDESC"]);
                        if (dt.Rows[k]["T_STARTTIME"] != null && dt.Rows[k]["T_STARTTIME"].ToString() != "")
                            ht.Add("startTime", sh.DateTimeToUTC(Convert.ToDateTime(dt.Rows[k]["T_STARTTIME"].ToString())));
                        else
                            ht.Add("startTime", dt.Rows[k]["T_STARTTIME"]);
                        if (dt.Rows[k]["T_ENDTIME"] != null && dt.Rows[k]["T_ENDTIME"].ToString() != "")
                            ht.Add("endTime", sh.DateTimeToUTC(Convert.ToDateTime(dt.Rows[k]["T_ENDTIME"].ToString())));
                        else
                            ht.Add("endTime", dt.Rows[k]["T_ENDTIME"]);
                        list.Add(ht);
                    }

                object obj = new
                {
                    page = page,
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationFaultInfoByType");
                sh.WriteLog("获取到参数：stationID:" + stationID);
                sh.WriteLog("获取到参数：type:" + type);
                sh.WriteLog("获取到参数：count:" + count);
                sh.WriteLog("获取到参数：pageIndex:" + pageIndex);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 获取故障类型
        [HttpGet]
        public HttpResponseMessage GetFaultType()
        {
            try
            {
                DeviceModel dm = new DeviceModel();
                IList<Hashtable> list = new List<Hashtable>();
                list = dm.List;

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetFaultType");
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 获取电站故障信息----正在发生的故障
        [HttpPost]
        public HttpResponseMessage GetStationRunningFault()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象
            StationModel sm = new StationModel();

            try
            {
                IList<Hashtable> list = new List<Hashtable>();
                DataTable dt = sm.DtFault;
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Hashtable ht = new Hashtable();
                        ht.Add("city", dt.Rows[i]["T_CITYDESC"]);
                        ht.Add("name", dt.Rows[i]["T_PLANTDESC"]);
                        ht.Add("inverterID", dt.Rows[i]["T_ORGID"]);
                        ht.Add("inverter", dt.Rows[i]["T_UNITDESC_CN"]);
                        ht.Add("faultName", dt.Rows[i]["T_FAULTDESC_CN"]);
                        ht.Add("faultGrade", dt.Rows[i]["T_TYPEDESC"]);
                        ht.Add("startTime", dt.Rows[i]["T_STARTTIME"]);

                        list.Add(ht);
                    }
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetStationRunningFault");
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #endregion

        #region APP 更新
        [HttpPost]
        public async Task<HttpResponseMessage> UploadFile()
        {
            bool bl = false;
            object obj = null;
            int code = 0;
            string versionCode = "";
            string type = "";
            string desc = "";
            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
                HttpRequestBase request = context.Request;//定义传统request对象

                string direction = HttpContext.Current.Server.MapPath("~/Android");
                if (!Directory.Exists(direction))
                {
                    Directory.CreateDirectory(direction);
                }
                string filename = "";
                var memoryStreamProvide = new MultipartMemoryStreamProvider();
                await Request.Content.ReadAsMultipartAsync(memoryStreamProvide);
                StringBuilder sbSql = new StringBuilder();
                Dictionary<string, string> dic = new Dictionary<string, string>();
                foreach (var item in memoryStreamProvide.Contents)
                {
                    if (item.Headers.ContentDisposition.FileName != null)
                    {
                        filename = item.Headers.ContentDisposition.FileName.Replace("\"", "");
                        string newFileName = direction + filename;
                        var ms = item.ReadAsStreamAsync().Result;
                        using (var br = new BinaryReader(ms))
                        {
                            var data = br.ReadBytes((int)ms.Length);
                            File.WriteAllBytes(newFileName, data);
                            System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(newFileName);
                        }
                    }
                    string name = item.Headers.ContentDisposition.Name;
                    if (name != null)
                    {
                        string value = item.ReadAsStringAsync().Result;
                        dic.Add(name, value);
                    }

                }
                code = Convert.ToInt32(dic["code"]);
                versionCode = dic["versionCode"];
                desc = dic["desc"];
                type = dic["type"];
                OtherModel om = new OtherModel(code, versionCode, type, desc, filename);
                bl = om.BlVersion;
                if (bl)
                {
                    obj = new
                    {
                        data = "上传成功"
                    };
                }
                else
                {
                    obj = new
                    {
                        data = "上传失败"
                    };
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("code:" + code);
                sh.WriteLog("versionCode:" + versionCode);
                sh.WriteLog("desc:" + desc);
                sh.WriteLog("type:" + type);
                sh.WriteLog(ex.Message);
                return null;
            }

        }
        //public async Task<HttpResponseMessage> UploadFile()
        //{
        //    bool bl = false;
        //    object obj = null;
        //    int code = 0;
        //    string versionCode = "";
        //    string type = "";
        //    string desc = "";
        //    try
        //    {
        //        HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
        //        HttpRequestBase request = context.Request;//定义传统request对象

        //        code = Convert.ToInt32(request.Form["code"]);
        //        versionCode = request.Form["versionCode"];
        //        desc = request.Form["desc"];
        //        type = request.Form["type"];

        //        string direction = @"D:\Android";//HttpContext.Current.Server.MapPath("~/App_Data");
        //        if (!Directory.Exists(direction))
        //        {
        //            Directory.CreateDirectory(direction);
        //        }

        //        var memoryStreamProvide = new MultipartMemoryStreamProvider();
        //        await Request.Content.ReadAsMultipartAsync(memoryStreamProvide);
        //        StringBuilder sbSql = new StringBuilder();
        //        foreach (var item in memoryStreamProvide.Contents)
        //        {
        //            if (item.Headers.ContentDisposition.FileName != null)
        //            {
        //                var filename = item.Headers.ContentDisposition.FileName.Replace("\"", "");
        //                string newFileName = direction + filename;
        //                var ms = item.ReadAsStreamAsync().Result;
        //                using (var br = new BinaryReader(ms))
        //                {
        //                    var data = br.ReadBytes((int)ms.Length);
        //                    File.WriteAllBytes(newFileName, data);
        //                    System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(newFileName);
        //                }
        //            }
        //        }
        //        OtherModel om = new OtherModel(code, versionCode, type, desc);
        //        bl = om.BlVersion;
        //        if (bl)
        //        {
        //            obj = new
        //            {
        //                data = "上传成功"
        //            };
        //        }
        //        else
        //        {
        //            obj = new
        //            {
        //                data = "上传失败"
        //            };
        //        }
        //        JavaScriptSerializer serializer = new JavaScriptSerializer();
        //        string str = serializer.Serialize(obj);
        //        HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        sh.WriteLog("code:" + code);
        //        sh.WriteLog("versionCode:" + versionCode);
        //        sh.WriteLog("desc:" + desc);
        //        sh.WriteLog("type:" + type);
        //        sh.WriteLog(ex.Message);
        //        return null;
        //    }
        //}


        [HttpPost]
        public HttpResponseMessage GetUrl(string version)
        {
            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
                HttpRequestBase request = context.Request;//定义传统request对象

                string type = request.Form["type"];
                OtherModel om = new OtherModel(type);

                DataTable dt = om.DtVersion;

                object obj = new
                {
                    code = dt.Rows[0]["T_CODE"],
                    versionCode = dt.Rows[0]["T_VERSIONCODE"],
                    desc = dt.Rows[0]["T_DESC"],
                    url = "Android/" + dt.Rows[0]["T_NAME"]
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch { return null; }
        }

        //[HttpGet]
        //public HttpResponseMessage GetUrl(string version)
        //{
        //    try
        //    {
        //        string url = "";
        //        string localVersion = SendUrl("https://192.168.70.34:8090/Api/API.txt");
        //        if (localVersion == version)
        //            url = "https://192.168.70.34:8090/Api/eInterconnect.plist";
        //        object obj = new
        //        {
        //            version = url
        //        };
        //        JavaScriptSerializer serializer = new JavaScriptSerializer();
        //        string str = serializer.Serialize(obj);
        //        HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
        //        return result;
        //    }
        //    catch { return null; }
        //}
        private string SendUrl(string Host)
        {
            try
            {
                string StrReturn = "";
                WebResponse result = null;

                WebRequest req = WebRequest.Create(Host);
                result = req.GetResponse();
                Stream ReceiveStream = result.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
                StreamReader sr = new StreamReader(ReceiveStream, encode);
                Char[] read = new Char[256];
                int count = sr.Read(read, 0, 256);

                StrReturn = new String(read, 0, count).Split(':')[1];

                if (result != null)
                {
                    result.Close();
                }
                return StrReturn.Trim();
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 十一科技AP
        [HttpPost]
        public HttpResponseMessage GetPlantListSYKJ()
        {
            try
            {

                //乌拉特一期 WLT-dis1
                //巴拉贡一期 BLG-dis1
                //巴音二期 BY-dis1
                //九十九泉一期  99Q-dis1
                //红牧一期 HM-dis1
                //润博一期 RB-dis1
                //胜利一期 SL-dis1

                string path = System.Web.HttpContext.Current.Request.MapPath("/");
                path += "Log\\" + @"dl.json";
                StreamReader read = new StreamReader(path);
                string jsonText = read.ReadToEnd();

                JArray array = (JArray)JsonConvert.DeserializeObject(jsonText);

                //for (int i = 0; i < array.Count; i++)
                //{
                //    //string name = array[i]["站名"].ToString();
                //    //string privince = array[i]["省份"].ToString();
                //    //string rl = array[i]["装机容量"].ToString();
                //    //string power = array[i]["实时负荷"].ToString();
                //    string dal2 = array[i]["2016-01"].ToString();
                //}

                string dal2 = "";




                //dal2 = array[0]["2016-01"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-1-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-02"].ToString();
                //for (int i = 0; i < 29; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-2-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-03"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-3-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-04"].ToString();
                //for (int i = 0; i < 30; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-4-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}


                //dal2 = array[0]["2016-05"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-5-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-06"].ToString();
                //for (int i = 0; i < 30; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-6-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}
                //dal2 = array[0]["2016-07"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-7-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}
                //dal2 = array[0]["2016-08"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-8-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-09"].ToString();
                //for (int i = 0; i < 30; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-9-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-10"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-10-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-11"].ToString();
                //for (int i = 0; i < 30; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-11-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2016-12"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2016-12-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = array[0]["2017-01"].ToString();
                //for (int i = 0; i < 31; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2017-1-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = "6.51,5.68,90.74,159.94,207.46,130.15,53.55,169.96,161.76,245,250.27,238.49,227.32,225.39,172.18,212.13,233.8,228.3,206.19,201.34,69.13,250.61,259.93,223.44,151.92,248.32,207.1,174.72";
                //for (int i = 0; i < 28; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2017-2-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}

                //dal2 = "143.61,227.55,242.65,226.91,171.75,156.16";
                //for (int i = 0; i < 6; i++)
                //{
                //    string sql = "insert into T_INFO_STATISTICS(T_TJID,T_ORGID,T_TIME,D_VALUE) values('DL','BY-dis1','2017-3-" + (i + 1) + " 0:00:00'," + Convert.ToDouble(dal2.Split(',')[i].Trim()) * 1000 + ");";
                //    OtherModel om = new OtherModel(sql);
                //    bool ju = om.BoolSql;
                //}



                IList<Hashtable> list = new List<Hashtable>();
                Hashtable ht = new Hashtable();
                ht.Add("name", "巴音光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "26.61");
                ht.Add("dl", "201.34");
                ht.Add("rl", "35000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "九十九泉光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "12.01");
                ht.Add("dl", "118.51");
                ht.Add("rl", "20000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "红牧光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "23.00");
                ht.Add("dl", "165.35");
                ht.Add("rl", "30000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "胜利光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "15.78");
                ht.Add("dl", "126.11");
                ht.Add("rl", "20000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "乌拉特光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "13.70");
                ht.Add("dl", "49.03");
                ht.Add("rl", "20000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "巴拉贡光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "8.93");
                ht.Add("dl", "36.95");
                ht.Add("rl", "10000");
                list.Add(ht);

                ht = new Hashtable();
                ht.Add("name", "润博光伏电站");
                ht.Add("privince", "内蒙古");
                ht.Add("power", "23.82");
                ht.Add("dl", "41.46");
                ht.Add("rl", "13000");
                list.Add(ht);

                object obj = new
                {
                    data = list
                };

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;

            }
            catch (Exception ex)
            {
                return null;
            }
        }
        #endregion

        #region 容量
        [HttpPost]
        public HttpResponseMessage GetRL()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Select(x => x["T_PLANTDESC"].ToString()).ToArray();
                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'");
                DataTable dtRL = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", stationID) + "'", "状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[0][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("state", state[0][i]);
                    DataRow[] drRL = dtRL.Select("T_ORGID ='" + stationID[i] + "'", "t_time desc");
                    if (drRL.Length > 0) ht.Add("rl", drRL[0]["D_RL"]);
                    else ht.Add("rl", null);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetRL");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetRLByPrivince()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站   
                DataTable dtCity = om.DtCity;

                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'");
                DataTable dtRL = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", stationID) + "'", "状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[0][i] != 0)
                    //{
                    string[] cityName = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[0]);
                    ht.Add("name", stationName[i]);
                    ht.Add("state", state[0][i]);
                    DataRow[] drRL = dtRL.Select("T_ORGID ='" + stationID[i] + "'", "t_time desc");
                    if (drRL.Length > 0) ht.Add("rl", drRL[0]["D_RL"]);
                    else ht.Add("rl", null);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetRLByPrivince");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetRLByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站   

                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();
                string[] cityName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'");
                DataTable dtRL = sm.AllRL;

                sm = new StationModel("'" + string.Join("','", stationID) + "'", "状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[0][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("state", state[0][i]);
                    DataRow[] drRL = dtRL.Select("T_ORGID ='" + stationID[i] + "'", "t_time desc");
                    if (drRL.Length > 0) ht.Add("rl", drRL[0]["D_RL"]);
                    else ht.Add("rl", null);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetRLByCity");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 负荷
        [HttpPost]
        public HttpResponseMessage GetPower()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站    

                string[] stationID = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "负荷,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[1][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("rl", state[0][i]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPower");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetPowerByPrivince()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站    
                DataTable dtCity = om.DtCity;

                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "负荷,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[1][i] != 0)
                    //{
                    string[] cityName = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("rl", state[0][i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[0]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPowerByPrivince");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetPowerByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站    

                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();
                string[] cityName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "负荷,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[1][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("rl", state[0][i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[i]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetPowerByCity");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 年电量
        [HttpPost]
        public HttpResponseMessage GetDL()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                DataTable dtDL = sm.ArrayDL;
                sm = new StationModel("'" + string.Join("','", stationID) + "'", "电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    double val = dtDL.AsEnumerable().Where(T => T.Field<string>("PLANTID") == stationID[i]).Sum(s => s.Field<double>("val"));

                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    //获取单个电站电量
                    if (DateTime.Now.Day == 1 && DateTime.Now.Month == 1)
                        ht.Add("dl", state[0][i]);
                    else
                        ht.Add("dl", sh.GetDouble(val + state[0][i], 2));

                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetDL");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetDLByPrivince()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站   
                DataTable dtCity = om.DtCity;

                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                DataTable dtDL = sm.ArrayDL;
                sm = new StationModel("'" + string.Join("','", stationID) + "'", "电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    double val = dtDL.AsEnumerable().Where(T => T.Field<string>("PLANTID") == stationID[i]).Sum(s => s.Field<double>("val"));
                    string[] cityName = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[0]);

                    //获取单个电站电量
                    if (DateTime.Now.Day == 1 && DateTime.Now.Month == 1)
                        ht.Add("dl", state[0][i]);
                    else
                        ht.Add("dl", sh.GetDouble(val + state[0][i], 2));

                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                }

                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetDLByPrivince");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetDLByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();
                string[] cityName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", Convert.ToDateTime(DateTime.Now.ToString("yyyy-1-1 0:00:00")), Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59")));
                DataTable dtDL = sm.ArrayDL;
                sm = new StationModel("'" + string.Join("','", stationID) + "'", "电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    double val = dtDL.AsEnumerable().Where(T => T.Field<string>("PLANTID") == stationID[i]).Sum(s => s.Field<double>("val"));

                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[0]);

                    //获取单个电站电量
                    if (DateTime.Now.Day == 1 && DateTime.Now.Month == 1)
                        ht.Add("dl", state[0][i]);
                    else
                        ht.Add("dl", sh.GetDouble(val + state[0][i], 2));

                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetDLByCity");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 总发电量
        [HttpPost]
        public HttpResponseMessage GetTotalDL()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "累计电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[1][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("dl", state[0][i]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用方法名称：GetTotalDL");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetTotalDLByPrivince()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];

            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站    
                DataTable dtCity = om.DtCity;
                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "累计电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    string[] cityName = dtCity.AsEnumerable().Where(T => T.Field<string>("T_PARENTID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                    //if (state[1][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[0]);
                    ht.Add("dl", state[0][i]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetTotalDL");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        [HttpPost]
        public HttpResponseMessage GetTotalDLByCity()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
            HttpRequestBase request = context.Request;//定义传统request对象

            string uid = request.Form["uid"];
            string id = request.Form["cityId"];
            try
            {
                IList<Hashtable> list = new List<Hashtable>();

                OrgModel om = new OrgModel(uid);
                DataTable dtStation = om.AllOrgStationInfo;          //所有用户电站      
                string[] stationID = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_ORGID"].ToString()).ToArray();
                string[] stationName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_PLANTDESC"].ToString()).ToArray();
                string[] cityName = dtStation.AsEnumerable().Where(T => T.Field<string>("T_CITYID") == id).Select(x => x["T_CITYDESC"].ToString()).ToArray();

                StationModel sm = new StationModel("'" + string.Join("','", stationID) + "'", "累计电量,状态".Split(','));
                List<double[]> state = sm.RealVal;

                for (int i = 0; i < stationID.Length; i++)
                {
                    //if (state[1][i] != 0)
                    //{
                    Hashtable ht = new Hashtable();
                    ht.Add("id", stationID[i]);
                    ht.Add("name", stationName[i]);
                    ht.Add("cityID", id);
                    ht.Add("cityName", cityName[i]);
                    ht.Add("dl", state[0][i]);
                    ht.Add("state", state[1][i]);
                    list.Add(ht);
                    //}
                }
                object obj = new
                {
                    data = list
                };
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string str = serializer.Serialize(obj);
                HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
                return result;
            }
            catch (Exception ex)
            {
                sh.WriteLog("异常===========================");
                sh.WriteLog("调用时间：" + DateTime.Now);
                sh.WriteLog("调用方法名称：GetTotalDLByCity");
                sh.WriteLog("获取到参数：uid=" + uid);
                sh.WriteLog("获取到参数：id=" + id);
                sh.WriteLog("异常内容：" + ex.Message);
                sh.WriteLog("异常===========================");
                return null;
            }
        }
        #endregion

        #region 牧羊人 APP





        #region 集团信息

        #region 电量（集团数据）

        #endregion

        #region 电站

        #endregion

        #region 历史报警

        #endregion

        #endregion

        #region 实时监控

        #endregion

        #region 即时聊天

        #endregion

        #region 个人信息

        #region 用户注册

        #endregion

        #region 用户修改密码

        #endregion

        #region 用户找回密码

        #endregion

        #endregion

        #endregion
    }
}

